import { ListNode } from "./listNode.js"
import { Solution } from "./solution.js"


const l1 = [1, 2, 3, 4, 5]
const l2 = [1, 2]
const l3 = []

let test = function(l, fun) {
    let node = ListNode.initWithList(l)
    if (node) {
        console.log(`翻转前: ${node.description()}`)    
    }else {
        console.log(`翻转前: null`)
    }
    
    let result = fun(node)
    if (result) {
        console.log(`翻转后: ${result.description()}`)
    }else {
        console.log(`翻转后: null`)
    }
    
}

console.log("----------cycle----------")
test(l1, Solution.reverseList)
test(l2, Solution.reverseList)
test(l3, Solution.reverseList)
console.log("----------recursion----------")
test(l1, Solution.reverseListByRecursion)
test(l2, Solution.reverseListByRecursion)
test(l3, Solution.reverseListByRecursion)